package org.jeecg.modules.rental.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.iot.req.CloseSocketReq;
import org.jeecg.modules.iot.req.OpenSocketReq;
import org.jeecg.modules.rental.service.ICtrlSocketService;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags="操控电单车信息")
@RestController
@RequestMapping("/ctrl/socket")
@RequiredArgsConstructor
public class CtrlSocketController {

    private final ICtrlSocketService ctrlSocketService;

    @GetMapping("/query-port/{deviceCode}")
    @ApiOperation("查询插座")
    public Result queryPort(@PathVariable String deviceCode) {
        Integer seq = ctrlSocketService.queryPort(deviceCode);
        return Result.ok("查询插座成功，序列号:" + seq);
    }

    @PostMapping("/open-port")
    @ApiOperation("打开插座")
    public Result openPort(@RequestBody OpenSocketReq req) {
        return ctrlSocketService.openPort(req);
    }

    @GetMapping("/closePort")
    @ApiOperation("关掉插座")
    public Result closePort(@RequestBody CloseSocketReq req) {
        return ctrlSocketService.closePort(req);
    }

}
